local sk__guiyuan = fk.CreateSkill {

  name = "sk__guiyuan",

  tags = {  },

}



sk__guiyuan:addEffect("active", {
  name = "sk__guiyuan",
  anim_type = "control",
  card_num = 0,
  target_num = 0,
  prompt = "#sk__guiyuan",
  can_use = function(self, player)
    return player:usedSkillTimes(sk__guiyuan.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    room:loseHp(player, 1, sk__guiyuan.name)
    if player.dead then return end
    local targets = room:getOtherPlayers(player)
    room:doIndicate(player.id, table.map(targets, Util.IdMapper))
    for _, target in ipairs(targets) do
      if player.dead then return end
      if not target.dead then
        local card = room:askForCard(target, 1, 1, false, sk__guiyuan.name, true, "peach", "#sk__guiyuan-give:"..player.id)
        if #card == 0 then
          local cards = table.filter(target:getCardIds("h"), function (id)
            return Fk:getCardById(id).trueName == "peach"
          end)
          if #cards > 0 then
            card = table.random(cards, 1)
          end
        end
        if #card > 0 then
          room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, sk__guiyuan.name, nil, true, target)
        end
      end
    end
    if not player.dead then
      local cards = room:getCardsFromPileByRule("peach", 1, "allPiles")
      if #cards > 0 then
        room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, sk__guiyuan.name, nil, true, player)
      end
    end
  end,
})

return sk__guiyuan